"""
文件写
    以什么方式写入,与文件类型无关,只与打开方式有关
"""
# 1.1 清空式写文件
file_path = "test.txt"
file_obj = open(file_path, 'w')

print(file_obj.write("ssdsdsdsadsadsadsadsadsdsdsdsadsdsads"))

print(file_obj.writelines(["ssdsdsdsadsadsadsadsadsdsdsdsadsdsads\n", "ssdsdsdsadsadsadsadsadsdsdsdsadsdsads\n",
                           "ssdsdsdsadsadsadsadsadsdsdsdsadsdsads\n"]))

file_obj.close()

# 1.2 追加式写文件
file_path = "test.txt"
file_obj = open(file_path, 'a')

print(file_obj.write("ssdsdsdsadsadsadsadsadsdsdsdsadsdsads"))

print(file_obj.writelines(["ssdsdsdsadsadsadsadsadsdsdsdsadsdsads\n", "ssdsdsdsadsadsadsadsadsdsdsdsadsdsads\n",
                           "ssdsdsdsadsadsadsadsadsdsdsdsadsdsads\n"]))

file_obj.close()

# 2.1 清空式写二进制(一个英文 一个字节; 一个汉字 三个字节)
file_path = "test.txt"
file_obj = open(file_path, 'wb')

print(file_obj.write("一二三".encode()))

print(file_obj.writelines(["灌灌灌灌灌过过过过过过过过过过过过过过过过过过过过过过过\n".encode(), "士大夫的感受对方答复dsdsdsdsadsdsads\n".encode(),
                           b"ssadsadsadasdsdsadsadsadsa\n"]))

file_obj.close()
